package me.xiaoyan.java.chapter15;

public class StringExample2 {

	public static void main(String[] args) {
		String words = "小白和小明玩，小明的玩具被小白抢了，小白很高兴，小明很伤心";
		//indexOf：位置
		int xiaoBaiPosition = words.indexOf("小白");
		System.out.println("第一个小白在:" + xiaoBaiPosition);
		//最后一个位置
		xiaoBaiPosition = words.lastIndexOf("小白");
		System.out.println("最后一个小白在:" + xiaoBaiPosition);
		// 截取字符串
		String str1 = words.substring(7);
		System.out.println(str1);
		//指定起、止位置
		String str2 = words.substring(7, 17);
		System.out.println(str2);
		
		words = "   小  白被人打了很高兴   ";
		String str3 = words.trim();
		System.out.println(str3);
		System.out.println(words.indexOf("小明"));
		
	}

}
